package com.yunsom.testdemo.multiple_thread.producer_customer.multiple_thread;

import java.util.concurrent.BlockingQueue;

public class Producer extends Thread{
    private BlockingQueue<Integer> buffer;

    public Producer(BlockingQueue buffer){
        this.buffer = buffer;
    }

    @Override
    public void run(){
        System.out.println("生产者生产中。。。");
        while (true){
            for (int i = 0; i < 100; i++) {
                System.out.println(Thread.currentThread().getName() + "生产数据" + i);
                try {
                    //blockingqueue的put方法会在队列满的时候阻塞等待
                    buffer.put(i);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "加入数据" + i);
            }
        }
    }
}
